<?php

namespace App\Admin\Tools\Task;

use App\Models\AdminUsersRelatedModel;
use App\Models\TaskModel;
use Encore\Admin\Grid\Tools\AbstractTool;

class TaskForwardTool extends AbstractTool
{
    private int $id;

    public function __construct(int $id)
    {
        $this->id = $id;
    }

    /**
     * @inheritDoc
     */
    public function render()
    {
        $array = AdminUsersRelatedModel::query()->leftJoin('admin_users', 'admin_users_related.user_id', 'admin_users.id')
            ->where('main_id', 1)->get(['user_id', 'name'])->toArray();

        $keys = array_column($array, 'user_id'); // 获取所有id
        $values = array_column($array, 'name'); // 获取所有name

        return view('task.forward', [
            'id' => $this->id,
            'user' => array_combine($keys, $values),
            'defaultUserId' => TaskModel::query()->where('id', $this->id)->value('follow_user_id')
        ]);
    }
}
